package com.ecar.apm.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.ecar.apm.model.HttpRequestLog;

@Mapper
public interface HttpRequestLogMapper {

	@Insert({"INSERT INTO http_request_log(pid,ppguid,pguid,`status`,`costTime`,`statusCode`,log)  VALUES(#{httpRequestLog.pid},#{httpRequestLog.ppguid},#{httpRequestLog.pguid},#{httpRequestLog.status},#{httpRequestLog.costTime},#{httpRequestLog.statusCode},#{httpRequestLog.log})"})
	  public abstract void insert(@Param("httpRequestLog") HttpRequestLog paramHttpRequestLog);
	  
	  @Select({"SELECT * FROM http_request_log"})
	  public abstract List<HttpRequestLog> selectAll();
	  
	  @Select({"select t.* from http_request_log t where t.pguid=#{pguid}"})
	  public abstract HttpRequestLog getByGuid(@Param("pguid") String paramString);
	  
	  @Delete({"delete from http_request_log where ppguid=#{ppguid}"})
	  public abstract void delete(@Param("ppguid") String paramString);
	  
	  @Select({"select r.httpMethod,r.url,t.`status`,t.statusCode,t.costTime,t.log from http_request_log t,http_request r where t.pguid=r.guid and t.pid=#{id}"})
	  public abstract List<Map<String, Object>> getByPid(@Param("id") int paramInt);
	  
	  @Delete({"delete from http_request_log where createTime < date_sub(curdate(),interval #{day} day)"})
	  public abstract void cleanLogByDay(@Param("day") int paramInt);
}
